﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core.UI.Controls;
using Baosight.Platform.Core;
using Baosight.Platform.Core.ServiceModel;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Baosight.ZNH.ZMCB.UI.Utils;

namespace Baosight.ZNH.ZMCB.UI
{
    /// <summary>
    /// 查询中长期计划-主表
    /// </summary>
    /// Copyright:Baosight Software LTD.co Copyright (c) 2011
    /// Company:上海宝信软件股份有限公司
    /// Author: 梁琦
    /// Version: 1.0
    /// History:
    ///       2013-07-08  梁琦   [创建]
    ///
    public partial class ZMCB25 : EFViewCmes
    {
        private Dictionary<object, string> TabToPageName; //存放页签与页面号的对应关系
        public ZMCB25()
        {
            InitializeComponent();
            TabToPageName = new Dictionary<object, string>();
            TabToPageName.Add(tab1, "ZMCB22");
            TabToPageName.Add(tab2, "ZMCB23");
            TabToPageName.Add(tab3, "ZMCB24");
            base.BeforeAction += OnBeforeAction;
        }

        /// <summary>
        /// 列表中修改、删除前设置属性、参数
        /// 传递到后台代码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.EFGridCheckedRows = this.grid.GetCheckedEIRows();
            base.ViewProperty = _view;
        }

        public override void Initialize(EIInfo initData)
        {
            YearPlanFTBlock block = new YearPlanFTBlock();
            initData.AddBlock(block.GetPlanStatus());
            base.Initialize(initData);
        }
        /// <summary>
        /// 选中主表一条记录，显示该条记录的从表数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void grid_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)
        {
            if (this.grid.SelectedItem != null)
            {
                LoadTab(this.grid.SelectedItem, this.tabPage.SelectedItem);
            }
            else
            {
                (this.tabPage.SelectedItem as EFTabItem).Content = null;
            }
        }

        /// <summary>
        /// 页签改变加载不同的页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EFTab_SelectionChanged(object sender, RoutedEventArgs e)
        {
            EFTab tab = sender as EFTab;
            if (this.grid.SelectedItem != null)
            {
                LoadTab(this.grid.SelectedItem, tab.SelectedItem);
            }
        }

        /// <summary>
        /// 加载不同的页签
        /// </summary>
        /// <param name="gridItem">列表中的一行数据</param>
        /// <param name="tabItem">EFTab控件对象</param>
        private void LoadTab(object gridItem, object tabItem)
        {
            var fdKeyId = gridItem.GetType().GetProperty("fdKeyId").GetValue(gridItem, null);
            Dictionary<string, string> args = new Dictionary<string, string>();
            args.Add("fdForeignId", fdKeyId.ToString());
            if (tabItem != null)
            {
                (tabItem as EFTabItem).Content = null;
                (tabItem as EFTabItem).LoadView(TabToPageName[tabItem], args);
            }
        }

        /// <summary>
        /// 明细
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            HyperlinkButton link = sender as HyperlinkButton;
            String fdKeyId = (link.ParentOfType<GridViewRow>().Item as UIBaseEntity).GetEIRow()["fdKeyId"].ToString();
            Dictionary<string, string> args = new Dictionary<string, string>();

            args.Add("fdKeyId", fdKeyId);
            Shell.LoadView("ZMCB20", args);
                //HyperlinkButton link = sender as HyperlinkButton;

            //EIRow row = (link.ParentOfType<GridViewRow>().Item as UIBaseEntity).GetEIRow();
            //EIInfo eiInfo = new EIInfo();
            //EIBlock eIBlock = new EIBlock("result");
            //eIBlock.SetRow(0, row == null ? new EIRow() : row);
            //eiInfo.AddBlock(eIBlock);

            //base.OnHyperlinkButtonClickPopup(eiInfo, "设备卡片-查看", "detail", null, sender, e);
        }
    }
}
